package com.candy.actiivemq.topic;

import com.candy.actiivemq.jms.CandyMessageListener;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.io.IOException;

/**
 * @author: candy
 * @date: 2020/9/20
 * @description :
 **/
public class ConsumerTopic {

    private final static String URL = "tcp://192.168.0.108:61616";

    public static void main(String[] args) throws JMSException, IOException {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(URL);
        Connection connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic myTopic = session.createTopic("MyTopic");
        MessageConsumer consumer = session.createConsumer(myTopic);

        consumer.setMessageListener(new CandyMessageListener());

        System.in.read();

        consumer.close();

        session.close();

        connection.close();
    }
}
